package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.PermissionDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = PermissionService.class)
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionDao permissionDao;

    /**
     * 查询所有添加权限的信息
     * @return
     */
    @Override
    public List<Permission> findAll() {
        return  permissionDao.findAll();
    }

    /**
     * 分页,条件查询权限的信息
     * @param qpb
     * @return
     */
    @Override
    public PageResult findPage(QueryPageBean qpb) {
        PageHelper.startPage(qpb.getCurrentPage(),qpb.getPageSize());
        Page<Permission> page = permissionDao.findByCondition(qpb.getQueryString());
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 添加一条权限数据
     * @param permission
     * @return
     */
    @Override
    public void add(Permission permission) {
        permissionDao.add(permission);
    }

    /**
     * 通过id查询出这条权限的信息
     * @param id
     * @return
     */
    @Override
    public Permission findById(Integer id) {
        return permissionDao.findById(id);
    }

    /**
     * 修改权限信息
     * @param permission
     * @return
     */
    @Override
    public void edit(Permission permission) {
        permissionDao.edit(permission);
    }

    /**
     * 通过id删除本条权限记录
     * @param id
     * @return
     */
    @Override
    public void delete(Integer id) {
        permissionDao.delete(id);
    }
}
